<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>管理平台</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
</head>
<body>
<div id="wrapper" class="row">
	
			<div class="col-lg-12">
				<h1 class="page-header">兑换商品标签</h1>
			</div>
			<div class="col-lg-12">
				<div class="col-lg-12">
					<div class=" col-lg-12">
						<div class="pull-right">
						<button type="button" class="btn btn-success" onclick="toAdd()"><span class="fa fa-plus"></span> 添加</button>
						<!-- <button type="button" class="btn btn-success" onclick="doSort()"><span class="fa fa-save"></span> 保存排序</button> -->
						</div>
					</div>
				</div>
				<div class="title-top col-lg-12">
					<form id="sortForm" action="${BASE_PATH}/wx/article/category/doSort" method="post">
					<input type="hidden" name="sortKey" value="orderNo">
					<table id="dataTable" class="table table-striped table-hover">
			            <thead>
			                <tr>
			                	<th width="15%">标签编号</th>
			                    <th width="20%">标签名称</th>
			                    <th width="15%">标签类型</th>
			                    <th width="25%">标签代码</th>
			                    <th width="5%">操作</th>
			                </tr>
			            </thead>
			            <tbody id="dataList"></tbody>
			        </table>
			        </form>
				</div>
		        	<div class="col-lg-12">
		        		<ul id="dataPagination" class="pagination-sm pull-right"></ul>
		        	</div>
		        </div>


</div>
<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 -->
<script type="text/html" id="dataTpl">
	{{each list as item}}
	<tr id="item{{item.id}}" data-id="{{item.id}}">
		<td>{{item.id}} </td>
		<td>{{item.title}} </td>
		<td>{{item.type}}</td>
		<td>{{item.titleCode}}</td>
		<td>
			<button type="button" class="btn btn-sm btn-primary btn-simple" onclick="toEdit('{{item.id}}')" title="编辑"><span class="fa fa-edit fa-lg"></span></button>
			<button type="button" class="btn btn-sm btn-primary btn-simple" onclick="doDelete('{{item.id}}')" title="编辑"><span class="fa fa-remove fa-lg"></span></button>
		</td>
	</tr>
	{{/each}}
</script>
<script type="text/javascript">
$(loadAll);
function loadAll(){
	$.post("${BASE_PATH}/wx/goodsTitle/list/",{"mp":"${mp}"},function(result){
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",{"list":result.object}));
	});
}
var addDialog;
function toAdd(){
	addDialog = Kit.dialog("添加","${BASE_PATH}/wx/goodsTitle/toAdd?mp=${mp}").open();
}
var editDialog;
function toEdit(id){
	editDialog = Kit.dialog("修改","${BASE_PATH}/wx/goodsTitle/toEdit/"+id).open();
}
function onEditSuccess(id,newObject){
	$("#item"+id).replaceWith(template("list-tpl",{"list":[newObject]}));
}
function doDelete(id){
	Kit.confirm("提示","您确定要删除这条数据吗？",function(){
		$.post("${BASE_PATH}/wx/goodsTitle/doDelete/"+id,function(result){
			if(result.flag==1){
				Kit.alert("存在商品");return;
			}else if(result.flag==0){
				$("#item"+id).remove();
			}else{
				Kit.alert("操作失败");return;
			}
		});
	});
}
/* function doSort(){
	$("#sortForm").ajaxSubmit({
		success:function(data){
			switch(data.flag){
			case -1:
				Kit.alert("网络繁忙...，请重试");return;
			case 0:
				window.location.reload();
			}
		}
	});
} */
</script>
</body>
</html>